package hivi.vn.hivigold.adapters;

import hivi.vn.hivigold.R;
import hivi.vn.hivigold.objects.Report;
import hivi.vn.hivigold.utils.Formats;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NXTAdapter extends BaseAdapter {
	ArrayList<Report> arr;
	Context context;
	public NXTAdapter(Context c, ArrayList<Report> arr) {
		// TODO Auto-generated constructor stub
		this.context = c;
		this.arr = arr;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arr.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arr.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		View v = arg1;
		BuyHolder bh;
		if(v==null)
		{
			v = ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.detail_report_nxt, null);
			bh = new BuyHolder();
			bh.txtNhom_hang = (TextView)v.findViewById(R.id.tvd_Nhomhang);
			bh.txtMa_hang = (TextView)v.findViewById(R.id.tvd_Ma_hang);
			bh.txtTen_hang = (TextView)v.findViewById(R.id.tvd_Ten_hang);
			bh.txtGia_von = (TextView)v.findViewById(R.id.tvd_gia_von);
			bh.txtSl_td = (TextView)v.findViewById(R.id.tvd_sl_td);
			bh.txtAu_td = (TextView)v.findViewById(R.id.tvd_tlgau_td);
			bh.txtDu_dau = (TextView)v.findViewById(R.id.tvd_du_dau);
			bh.txtSl_nhap = (TextView)v.findViewById(R.id.tvd_sl_nhap);
			bh.txtAu_nhap = (TextView)v.findViewById(R.id.tvd_tlgau_nhap);
			bh.txtTien_nhap = (TextView)v.findViewById(R.id.tvd_tien_nhap);
			bh.txtSl_xuat = (TextView)v.findViewById(R.id.tvd_sl_xuat);
			bh.txtAu_xuat = (TextView)v.findViewById(R.id.tvd_tlgau_xuat);
			bh.txtTien_xuat = (TextView)v.findViewById(R.id.tvd_tien_xuat);
			bh.txtSl_tc = (TextView)v.findViewById(R.id.tvd_sl_tc);
			bh.txtAu_tc = (TextView)v.findViewById(R.id.tvd_tlgau_tc);
			bh.txtDu_cuoi = (TextView)v.findViewById(R.id.tvd_du_cuoi);
			v.setTag(bh);
		}else
		{
			bh = (BuyHolder)v.getTag();
		}
		Report r = arr.get(arg0);
		bh.txtNhom_hang.setText(r.getNhom_hang());
		bh.txtMa_hang.setText(r.getMa_hang());
		bh.txtTen_hang.setText(r.getTen_hang());
		bh.txtGia_von.setText(Formats.money(r.getGia_von()/1000));
		bh.txtSl_td.setText(Formats.number(r.getSl_td()));
		bh.txtAu_td.setText(Formats.number(r.getAu_td()));
		bh.txtDu_dau.setText(Formats.money(r.getDu_dau()/1000));
		bh.txtSl_nhap.setText(Formats.number(r.getSl_nhap()));
		bh.txtAu_nhap.setText(Formats.number(r.getAu_nhap()));
		bh.txtTien_nhap.setText(Formats.money(r.getTien_nhap()/1000));
		bh.txtSl_xuat.setText(Formats.number(r.getSl_xuat()));
		bh.txtAu_xuat.setText(Formats.number(r.getAu_xuat()));
		bh.txtTien_xuat.setText(Formats.money(r.getTien_xuat()/1000));
		bh.txtSl_tc.setText(Formats.number(r.getSl_tc()));
		bh.txtAu_tc.setText(Formats.number(r.getAu_tc()));
		bh.txtDu_cuoi.setText(Formats.money(r.getDu_cuoi()/1000));
		return v;
	}

	static class BuyHolder
	{
		TextView txtNhom_hang;
		TextView txtMa_hang;
		TextView txtTen_hang;
		TextView txtSl_td;
		TextView txtAu_td;
		TextView txtGia_von;
		TextView txtDu_dau;
		TextView txtAu_nhap;
		TextView txtSl_nhap;
		TextView txtTien_nhap;
		TextView txtAu_xuat;
		TextView txtSl_xuat;
		TextView txtTien_xuat;
		TextView txtAu_tc;
		TextView txtSl_tc;
		TextView txtDu_cuoi;
	}
}
